package com.wu.dms.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wu.common.convertion.exception.ClientException;
import com.wu.dms.dao.entity.Admin;
import com.wu.dms.dao.mapper.AdminMapper;
import com.wu.dms.dto.AdminRequestDTO;
import com.wu.dms.service.AdminService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 *
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    /**
     * @param requestParam 请求参数，包含用户名和密码
     */
    @Override
    public void verityPasswd(AdminRequestDTO requestParam, HttpSession session) {
        // 查询数据库中具有给定用户名和密码的管理员用户
        List<Admin> list = query().eq("name", requestParam.getUsername())
                .eq("password", requestParam.getPassword()).list();

        // 检查用户是否存在
        if (CollectionUtil.isEmpty(list)) {
            throw new ClientException("用户名或密码不正确");
        }

        // 将用户名存储在会话中
        session.setAttribute("name", requestParam.getUsername());
    }
}

